<!--
 * @Description: 病虫害记录
-->
<template>
  <BaseMainSlot>
    <template v-slot:zhactbar>
      <ActionBar
        :page-no="15"
        :has-add="false"
        :has-del="false"
        :has-edit="false"
        :has-cancel="false"
        :has-edit-column="true"
        @showColumn="showColumn"
      />
    </template>
    <template v-slot:searchbox>
      <SearchForm :formConfig="formConfig" :formData="searchlist" @search="search"></SearchForm>
    </template>
    <template v-slot:content>
      <Table @sortChange="changeTableSort" :propList="tableColumn" v-loading="loading" :listData="tableData" :showSelectColumn="false">
        <template v-slot:operation="{ row }">
          <template v-if="!row.index">
            <el-button
              v-if="row.disposeFlag === 2 && judgePermission(15, 'edit')"
              type="warning"
              plain
              @click="showdighandleview(row)"
            >处理</el-button>
            <el-button
              v-if="row.disposeFlag !== 2 && judgePermission(15, 'edit')"
              type="info"
              disabled
              @click="showdighandleview(row)"
            >处理</el-button>
          </template>
        </template>
        <template v-slot:disposeDate="{ row, item }">
          <template v-if="!row.index">
            {{ dateToFormat(row[item.prop]) }}
          </template>
        </template>
        <template v-slot:disposeFlag="{ row }">
          <template v-if="!row.index">
            <div v-if="row.disposeFlag === 2" style="color:#e01c1c;">需要处理</div>
            <div v-if="row.disposeFlag === 3" style="color:rgba(32,255,0,1)">不需要处理</div>
            <div v-if="row.disposeFlag === 1" style="color:#d3e01c;">暂未处理</div>
          </template>
        </template>
      </Table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </template>
    <template v-slot:dig>
      <el-dialog title="图片" :visible.sync="showpicview" width="30%">
        <img style="width:100%;height:100%" :src="pictviewurl" />
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="showpicview = false">取 消</el-button>
          <el-button class="zh-button-two" type="primary" @click="showpicview = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 信息处理弹框 -->
      <el-dialog title="处理告警" :visible.sync="isshowhandleview" width="30%">
        <div>
          <!-- <div style="width:100%;display:flex;color:#fff;height:40px;line-height:40px;">
            <div style="width:120px;">是否需要处理:</div>
            <el-select v-model="handlemessage.disposeFlag" :placeholder="'选择是否需要处理'">
              <el-option v-for="disposeActionitem in disposeActionList" :key="disposeActionitem.id" :label="disposeActionitem.name" :value="disposeActionitem.id" />
            </el-select>
          </div>-->
          <div
            v-if="handlemessage.disposeFlag === 2"
            style="width:100%;display:flex;color:#fff;height:40px;line-height:40px;"
          >
            <div style="width:120px;">操作处理:</div>
            <el-select v-model="handlemessage.disposeAction">
              <el-option
                v-for="handtypeitem in handingtypeList"
                :key="handtypeitem.id"
                :label="handtypeitem.name"
                :value="handtypeitem.id"
              />
            </el-select>
          </div>
          <div
            v-if="handlemessage.disposeAction === 2"
            style="width:100%;display:flex;color:#fff;height:40px;line-height:40px;"
          >
            <div style="width:120px;">请输入:</div>
            <div style="width:50%">
              <el-input v-model="handlemessage.insectDisposeDes" />
            </div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="isshowhandleview = false">取 消</el-button>
          <el-button class="zh-button-two" type="primary" @click="handlemessagemet()">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog title="处理告警" :visible.sync="isshowhandleviewtwo" width="30%">
        <div>
          <div style="width:100%;display:flex;color:#fff;height:40px;line-height:40px;">
            <div style="width:120px;">是否需要处理:</div>
            <el-select v-model="handlemessage.disposeFlag" :placeholder="'选择是否需要处理'">
              <el-option
                v-for="disposeActionitem in disposeActionList"
                :key="disposeActionitem.id"
                :label="disposeActionitem.name"
                :value="disposeActionitem.id"
              />
            </el-select>
          </div>
          <!-- <div v-if="handlemessage.disposeFlag === 2" style="width:100%;display:flex;color:#fff;height:40px;line-height:40px;">
            <div style="width:120px;">操作处理:</div>
            <el-select v-model="handlemessage.disposeAction">
              <el-option v-for="handtypeitem in handingtypeList" :key="handtypeitem.id" :label="handtypeitem.name" :value="handtypeitem.id" />
            </el-select>
          </div>
          <div v-if="handlemessage.disposeAction === 2" style="width:100%;display:flex;color:#fff;height:40px;line-height:40px;">
            <div style="width:120px;">请输入:</div>
            <div style="width:50%"><el-input v-model="handlemessage.insectDisposeDes" /></div>
          </div>-->
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="isshowhandleviewtwo = false">取 消</el-button>
          <el-button class="zh-button-two" type="primary" @click="handlemessagemet()">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        id="tableColumnDialog"
        title="配置列"
        :visible.sync="dialogTableColumnVisible"
      >
        <tableColumn
          v-if="dialogTableColumnVisible"
          ref="tableColumn"
          :tableColumn="allTableColumn"
          @cancelColumn="cancelColumn"
        />
        <div slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="dialogTableColumnVisible = false">
            取 消
          </el-button>
          <el-button
            class="zh-button-two"
            type="primary"
            @click="saveColumn"
          >
            保 存
          </el-button>
        </div>
      </el-dialog>
    </template>
  </BaseMainSlot>
</template>

<script>
// import facgroupreq from "@/api/user/index"
import SearchForm from '@/components/searchForm';
import Table from '@/components/table/table.vue';
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import nowpagereq from "@/api/digital-production/pest-management/pest-zhalarm/index";
import BaseMainSlot from "@/components/BaseMainSlot/baseone.vue";
import { mymixin } from "@/utils/mixin";
import { getToken } from "@/utils/auth";
import { farmingTypeTitle } from "@/utils/validate";
import { mapGetters } from "vuex";

export default {
  name: "PestZhalarm",
  components: { Table, ActionBar, Pagination, BaseMainSlot, SearchForm },
  mixins: [mymixin],
  data() {
    var farmingTypeTitles = farmingTypeTitle()
    return {
      tableColumn: [
        { prop: 'alarmBatchName', label: '批次名称' },
        { prop: 'alarmTypeName', label: '告警类别' },
        { prop: 'alarmDes', label: farmingTypeTitles+'信息' },
        { prop: 'alarmStartDate', label: '告警开始时间', slotName: 'disposeDate' },
        { prop: 'disposeMan', label: '告警处理人' },
        { prop: 'disposeFlag', label: '处理状态', slotName: 'disposeFlag' },
        { prop: 'operation', label: '操作', slotName: 'operation', width: "140" }
      ],
      formConfig: [
        {
          label: '批次选择',
          prop: 'batchNo',
          type: 'select',
          options: [], // batchList
          optionKey: { label: 'batchName', value: 'batchId' },
        }, {
          label: '记录时间',
          prop: 'date',
          type: 'daterange',
        },
      ],
      showpicview: false,
      pictviewurl: "",
      // 是否有病虫害
      ispestlist: [
        { name: "病害", value: "1" },
        { name: "虫害害", value: "2" }
      ],
      farmingTypeTitles: farmingTypeTitle(),
      // -------
      // 当前物联数据日期选择
      zhdateList: "",
      // 当前选中的病虫害图片id
      nowsectpictureid: "",
      state1: "",
      // 处理类别选择
      handingtypeList: [
        { name: "处理完成", id: 1 },
        { name: "其他", id: 2 }
      ],
      // 是否需要处理
      disposeActionList: [
        { name: "还未处理", id: 1 },
        { name: "是", id: 2 },
        { name: "否", id: 3 }
      ],
      // 可选择批次列表
      batchList: [],
      isshowhandleview: false,
      isshowhandleviewtwo: false,
      handlemessage: {
        insectAlarmId: "",
        disposeAction: "", // 处理类别
        disposeFlag: "", // 是否需要处理
        insectDisposeDes: "" // 虫害处理信息
      },
      // 可选择所有地块
      //   facilityList: [],
      // 所搜索框内容
      searchlist: {},
      pickerOptionsone: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          }
        ]
      }
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  watch: {
    // nowChanceStau(newval) {
    //   this.getselectdatalist()
    //   this.nowplantTypeName = "种养类别"
    // }
  },
  created() {},
  mounted() {
    this.getTableDataList();
    this.getselectdatalist();
  },
  methods: {
    // 获取下拉框数据
    getselectdatalist() {
      // 获取所有批次
      nowpagereq.getallbatchList().then(res => {
        this.batchList = res.data;
        this.formConfig[0].options = res.data;
      });
    },
    // 表格查询
    getTableDataList() {
      this.loading = true;
      this.tableData = [];
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        sortList: this.sortList || [],
        entity: {
          disposeAction: 2,
          organizationNo: getToken("organizationNo"),
          alarmBatchId: this.searchlist.batchNo || undefined
        }
      };
      if (this.searchlist.date) {
        params.entity.startTime1 = this.dateToFormat(this.searchlist.date[0]);
        params.entity.endTime1 = this.dateToFormat(this.searchlist.date[1]);
      }
      this.entity = params.entity
      nowpagereq.getlist(params).then(res => {
        if (res.code === 1) {
          // this.$message.success('查询成功')
        } else {
          this.$message.error("查询失败");
        }
        this.loading = false;
        let data = res.data;
        // 赋值总条数
        this.totalSize = data.totalElements;
        // 赋值数组
        this.tableData = data.content;
        this.addblankmet();
        this.resetActionBar();
      });
    },
    // 获取图片详情
    getpicmessage(id) {
      // let id = idlist[0].pictureId
      this.showpicview = true;
      this.pictviewurl = `${this.$baseurl.webServiceUrl}productionv2/growthProcessPicture/query/${id}`;
      // nowpagereq.getpicmessage(id).then(
      //   res => {
      //     console.log(res)
      //   }
      // )
    },
    search() {
      this.currentPage = 1;
      this.getTableDataList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.getTableDataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.getTableDataList();
    },
    // 删除时触发方法
    delmessage() {},
    // 展示处理弹框
    showdighandleview(e) {
      this.handlemessage = {
        insectAlarmId: e.insectAlarmId,
        disposeAction: "", // 处理类别
        disposeFlag: e.disposeFlag, // 是否需要处理
        insectDisposeDes: "" // 虫害处理信息
      };
      if (e.disposeFlag === 2) {
        this.isshowhandleview = true;
      } else {
        this.$message.warning("该条告警不需要处理！");
      }
    },
    // 展示处理弹框
    showdighandleviewtwo(e) {
      this.isshowhandleviewtwo = true;
      this.handlemessage = {
        insectAlarmId: e.insectAlarmId,
        // disposeAction: "", // 处理类别
        disposeFlag: "" // 是否需要处理
        // insectDisposeDes: "" // 虫害处理信息
      };
    },
    handlemessagemet() {
      // if (this.handlemessage.disposeAction === 2 && this.handlemessage.insectDisposeDes.length === 0) {
      //   this.$message.warning("请填写信息！")
      //   return
      // }
      let params = {
        ...this.handlemessage
      };
      nowpagereq.editlist(params).then(res => {
        if (res.code === 1) {
          this.$message.success("处理成功");
          this.getTableDataList();
          this.isshowhandleview = false;
          this.isshowhandleviewtwo = false;
        } else {
          this.$message.warning("处理失败");
        }
      });
    },
    save() {
      // -----保存状态判断-----
    }
  }
};
</script>

<style scoped lang="scss">
::v-deep .el-checkbox {
  .el-checkbox__label {
    color: #dbe9e9;
    color: #d3e01c;
    // flex-direction: column;
  }
}

::v-deep .el-dialog__wrapper {
  .el-dialog {
    width: 20% !important;
    min-width: 30%;
    height: 30vh;
    .el-dialog__header .el-dialog__title {
      color: #dbe9e9;
    }

    div {
      color: #000;
    }
    .el-dialog__body {
      height: 18vh;
    }

    //   background-color:  #005d7b;
    //   border: #23fff8 1px solid;
    //   white-space: nowrap;
    //   ::v-deep .el-input__inner{
    //       color: #dbe9e9 !important;
    //   }
    // }
    // ::v-deep .el-dialog .el-select .el-input__inner {
    //   color: #dbe9e9 !important;
  }
}
</style>
